package com.wc.算法基础课.E第五讲动态规划.区间DP.密码脱落;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/29 11:31
 * @description https://www.acwing.com/problem/content/1224/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static int[][] f = new int[N][N];
    static char[] s = new char[N];

    // 思路：考虑一个字符串最长长度，就考虑首部和尾部是否相同，相同就是f[i + 1][j - 1] + 2
    //      如果不相同呢 就是包括左边不包括右边f[i][j - 1],反之 f[i + 1][j]
    public static void main(String[] args) {
        s = (" " + sc.next()).toCharArray();
        int n = s.length - 1;

        for (int len = 1; len <= n; len++) {
            for (int i = 1; i + len - 1 <= n; i++) {
                int j = i + len - 1;
                if (len == 1) f[i][j] = 1;
                else {
                    f[i][j] = Math.max(f[i][j], f[i + 1][j]);
                    f[i][j] = Math.max(f[i][j], f[i][j - 1]);
                    if (s[i] == s[j])
                        f[i][j] = Math.max(f[i][j], f[i + 1][j - 1] + 2);
                }
            }
        }
        out.println(n - f[1][n]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
